package gameserver;
import java.net.Socket;

/** A thread to manage pending clients who have connected. **/
public class ClientGreeterThread extends Thread {

    public Server server = null; // corresponding server

    public ClientGreeterThread() {
        super("ClientGreeterThread");
    }

    public ClientGreeterThread(Server server) {
        super("ClientGreeterThread");
        this.server = server;
    }

    /** Runs a loop to accept new clients and add them to the client list. **/
    @Override
    public void start() {
        try {
            while (server.mode == SGSGlobal.ON) {
                Socket sock = server.serverSocket.accept(); // wait for client
                server.clients.add(new Connection(server, sock)); // add to client list
            }
        } catch (Exception e) {
            System.out.println("Error: " + e.getMessage());
        }
    }
}
